package com.nowcoder.code.lcof;

import java.util.Stack;

public class JZ30 {
    public static void main(String[] args) {
        JZ30 jz30 = new JZ30();
        jz30.push(-1);
        jz30.push(2);
        System.out.println(jz30.min);
        System.out.println(jz30.top());
        jz30.push(1);
        System.out.println(jz30.top());
        System.out.println(jz30.min);

    }

    Stack<Integer> tmp = new Stack<>();
    Stack<Integer> min = new Stack<>();

    public void push(int node) {
        tmp.push(node);
        if (min.isEmpty()) {
            min.push(node);
        } else {
            min.push(Math.min(min.peek(), node));
        }
    }

    public void pop() {
        tmp.pop();
        min.pop();
    }

    public int top() {
        return tmp.peek();
    }

    public int min() {
        return min.peek();
    }

}
